<template>
  <div id="asn"
       v-loading="loading">
    <v-tableTitle :btnConfig="btnConfig"
                  :tableSelectData="tableSelectData"
                  :title="$t('in.rtxqc')"
                  @exportAsn="exportAsn"></v-tableTitle>
    <v-table :pageSize="pageSize"
             :page="page"
             :tableConfig="tableConfig"
             :tableData="tableData"
             :total="total"
             @findData="getTableData"
             @getTableData="getTableData"
             @searhData="searhData"
             @selectData="selectData"
             @setdialog="setdialog"
             @upData="getTableData"
             ref="table"></v-table>
  </div>
</template>

<script type="text/ecmascript-6">
import drawer from "./deawer/Deawer"
import tableTitle from "commons/TableTitle";
import table from "commons/Table";
import baseMixin from "@/mixins/BaseMixin";
import config from "./Config";
import bus from "../../../../bus/bus"

export default {
  name: "rtxqc",
  mixins: [baseMixin, config],
  data () {
    return {
      loading: false,
      tableConfig: [
        {
          label: this.$t('in.receiptkey'),
          prop: "receiptkey",
          input: "input",
          disabled: false
        },
        {
          label: this.$t('in.receiptdate'),
          prop: "receiptdate",
          input: "date",
          width: '150px',
          disabled: false
        },
        {
          label: this.$t('in.rtxbatch'),
          prop: "rtxbatch",
          input: "input",
          disabled: false
        },
        {
          label: this.$t('in.rtxchecklist'),
          prop: "rtxchecklist",
          input: "input",
          disabled: false
        },
        {
          label: this.$t('in.editwho'),
          prop: "rtxchecker",
          input: "input",
          disabled: false
        },
        {
          label: this.$t('in.rtxcheckdate'),
          prop: "rtxcheckdate",
          input: "date",
          width: '150px',
          disabled: false,
        },
        {
          label: this.$t('in.rtxdept'),
          prop: "rtxdept",
          input: "input",
          disabled: false
        },
        {
          label: this.$t('in.rtxstandard'),
          prop: "rtxstandard",
          input: "select",
          disabled: false,
          options: this.getOptions("codelkup/ACCEPTANCESTANDARD")
        },
        {
          label:  this.$t('app.remark'),
          prop: "rtxremark",
          input: "input",
          disabled: false
        },
        {
          label: this.$t('in.rtxresult'),
          prop: "rtxresult",
          input: "select",
          disabled: false,
          options: this.getOptions("codelkup/RTXRESULT")
        },
        {
          label: this.$t('in.rtxqcqty'),
          prop: "rtxqcqty",
          input: "input",
          disabled: false
        },
        {
          label: this.$t('in.rtxokqty'),
          prop: "rtxokqty",
          input: "input",
          disabled: false
        },
        {
          label: this.$t('in.rtxngqty'),
          prop: "rtxngqty",
          input: "input",
          disabled: false
        }
      ],
      tableData: [],
      page: 1,
      pageSize: 10,
      total: 0,
      tableSelectData: [],
      tableSearhData: {},
    };
  },
  computed: {
    btnConfig () {
      return [
        { label: this.$t('common.export'), certigier: this.downloadStatus||!this.btnPermNameList.includes('WM010701'), disabled: true, invalid: "exportAsn" },
      ]
    }
  },
  created () {
  },
  methods: {

    //导出
    async exportAsn (data) {
      try {
        let res = await this.$api.post('/exportRtxQc', data, { responseType: 'blob' })
        if (window.navigator.msSaveBlob) {
          var blobObject = new Blob([res.data]);
          window.navigator.msSaveBlob(blobObject, 'asn.xls');
        } else {
          var blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=utf-8' });
          var filename = 'rtxqc.xls';
          var downloadElement = document.createElement('a');
          var href = window.URL.createObjectURL(blob); //创建下载的链接
          downloadElement.style.display = 'none';
          downloadElement.href = href;
          downloadElement.download = filename; //下载后文件名
          document.body.appendChild(downloadElement);
          downloadElement.click(); //点击下载
          document.body.removeChild(downloadElement); //下载完成移除元素
          window.URL.revokeObjectURL(href); //释放掉blob对象
        }
      } catch (e) {
        this.$message.error(e);
      } finally {
        
      }
    },

    //选中的内容
    selectData (data) {
      this.tableSelectData = data;
    },
    async getTableData (page, data) {
      try {
        this.loading = true;
        let res = await this.$api.post(`/queryRtxQcList/${page}`, data);
        
          this.tableData = res.page.list;
          this.page = res.page.curPage;
          this.pageSize = res.page.pageSize;
          this.total = res.page.total;
        
      } catch (e) {
        this.$message.error(e);
      } finally {
        this.loading = false;
      }
    },
    //搜索的值
    searhData (data, up) {
      if (!up) {
        this.tableSearhData = data;
      } else {
        this.tableSearhData = data;
        this.getTableData(1, this.tableSearhData);
      }
    },
    //设置弹框
    setdialog (data) {
      this.$store.commit("setRouteData", data);
      this.$router.push({ name: 'rtxqcDeawer' });

    },

  },
  mounted () {
    this.$store.commit("setSkip", {});
    this.$store.commit("setRouteId", '');
    this.$store.commit("setNewFlag", false);
    this.$store.commit("setRouteData", {});
    this.$store.commit("setTemporary", "")
    this.getTableData(1, {});
  },
  watch: {
    tableSelectData (data) {
      if (this.permissionStatus) {
        if (data.length > 0) {
          this.deleteStatus = this.downloadStatus = this.actionStatus = this.blindActionStatus = false;
        } else {
          this.deleteStatus = this.downloadStatus = this.actionStatus = this.blindActionStatus = true;
        }
      }
    }
  },
  components: {
    "v-tableTitle": tableTitle,
    "v-table": table,
    "v-drawer": drawer
  }
};
</script>

<style scoped>
#asn {
  width: 100%;
  height: 99%;
  padding-top: 6px;
}
</style>
